package JUC.线程池.队无界;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 池固定coreSize 队列无限
 * （核心线程数 = 最大线程数相同
 */
public class UseFixedPool {
    public static void main(String[] args) {
        useFixed();
    }

    private static void useFixed() {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        for (int i = 0; i < 5; i++) { // for 应该套住 execute -> 一个个start
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName());

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        executorService.shutdown();
    }
}
/**
 * pool-1-thread-1
 * pool-1-thread-3
 * pool-1-thread-2
 * ... 1s后
 * pool-1-thread-1
 * pool-1-thread-3
 */